var http = require("http");
var url = require("url");
var handles = {};
handles["/"] = start;
handles["/start"] = start;
handles["/upload"] = upload;

function startServer(handles,route){
	http.createServer(function(request, response){
		var pathname = url.parse(request.url).pathname;
		var content = route(handles,pathname);
		response.writeHead(200 , {"Content-Type" : "text/plain"});
		response.write(content);
		response.end();
	}).listen(8888);
}

function start(){
	console.log("Require for 'start' is called");
	return "start"; 
}

function upload(){
	console.log("Require for 'upload' is called");
	return "upload";
}

function route(handles, pathname){
	console.log("route processor");
	if(typeof handles[pathname] == 'function'){
		return handles[pathname]();
	}else{
		console.log("There is not the path");
		return "404 NOT FOUND";
	}
}

startServer(handle,route);